﻿using CatUtils.Utils.Currency;
using CatUtils.Utils.Currency.IoUtils;
using CatUtils.Utils.Currency.TextUtils;
using CatUtils.Utils.SpecialUtils.Html;
using System;
using System.Collections.Generic;

namespace SinaImgUpload.SainTool.LocalTool
{
    internal class ClearWithPixivId
    {     /// <summary>
          /// 导出图床列表列表
          /// </summary>
          /// <param name="BedFilePath"></param>
        public void SingleXmlFile(String BedFilePath, string MinCountText)
        {
            int MinCount = TextHelper.StringToInt(MinCountText);
            List<string> imgInfos = HtmlHelper.GetHtmlValueList(FileHelper.ReadAllText(BedFilePath), "//bed");
            string NewFilePath = FileNameHelper.CreateFileNameWithChildFloder(BedFilePath, "清理ID小于" + MinCount);
            int CompltedCount = 0;
            foreach (string Single in imgInfos)
            {
                new PrintLog().PercentLog(imgInfos.Count, ++CompltedCount);
                string PixivLink = HtmlHelper.GetFirstText(Single, "//sina");
                string PixivIdText = TextHelper.RegexText(PixivLink, "/[0-9]{1,}_p");
                PixivIdText = TextHelper.ReplaceTextEnhance(PixivIdText, "(/|_p)", "");
                int PixivID = TextHelper.StringToInt(PixivIdText);

                if (PixivID < MinCount)
                {
                    Console.WriteLine("画作：{0}小于预设值{1}，跳过。", PixivID, MinCount);
                    continue;
                }

                FileHelper.AppendText(NewFilePath, PixivLink);
            }
        }

        /// <summary>
        /// 批量清理失效Sain链接
        /// </summary>
        /// <param name="FloderPath"></param>
        internal void ClearXmlWithFloder(string FloderPath, string MinCountText)
        {
            List<string> FoloderList = FloderNameHelper.GetFullFileNameList(FloderPath, "*.lst");
            foreach (string line in FoloderList)
            {
                Console.WriteLine(line);
                SingleXmlFile(line, MinCountText);
            }
        }
    }
}